﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Swashbuckle.AspNetCore.Annotations;

namespace Journeo_backend.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    [AllowAnonymous]
    public class RegionController : ControllerBase
    {
        private readonly IRegionService _regionService;

        public RegionController(IRegionService regionService)
        {
            _regionService = regionService;
        }

        [HttpGet("detail/{regionId}")]
        [SwaggerOperation(Summary = "通过地区ID获取地区详情", Description = "通过地区ID获取地区详情")]
        [SwaggerResponse(200, "获取成功", typeof(Response<Region>))]
        [SwaggerResponse(400, "获取失败")]
        public async Task<IActionResult> GetRegionDetailById(long regionId)
        {
            var response = await _regionService.GetRegionDetailById(regionId);
            return Ok(response);
        }


        [HttpGet("cities/{parentId}")]
        [SwaggerOperation(Summary = "通过省级ID获取市级列表", Description = "通过省级ID获取市级列表")]
        [SwaggerResponse(200, "获取成功", typeof(PageResponse<Region>))]
        [SwaggerResponse(400, "获取失败")]
        public async Task<IActionResult> GetRegionsByParentId(int pageNumber, int pageSize, long parentId)
        {
            var response = await _regionService.GetRegionsByParentId(pageNumber, pageSize, parentId);
            return Ok(response);
        }
    }
}
